const {ipcMain} = require('electron');
const db = require('../service/db');

function registerDBIpc() {
    // 获取考题列表
    ipcMain.handle('db:getQuesList', async (event, {limit, offset, type, rating, sortByDiff, sortByCount}) => {
        return await db.getQuesListWithPagination(limit, offset, type, rating, sortByDiff, sortByCount);
    });

    // 获取考题总数
    ipcMain.handle('db:getQuesCount', async (event, {type, rating}) => {
        return await db.getQuesCount(type, rating);
    });

    ipcMain.handle('db:getQuesTypes', async (event, {rating}) => {
        return await db.getQuesTypes(rating);
    });

    ipcMain.handle('db:getQuesRatingRanges', async (event, {type}) => {
        return await db.getQuesRatingRanges(type);
    });

    ipcMain.handle('db:getRandomIdList', async (event, {count, type, rating, exclude}) => {
        return await db.getRandomIdList(count, type, rating, exclude);
    });
}

module.exports = registerDBIpc;